//
//  LanguageResultCell.swift
//  
//
//  Created by CSS on 8/17/23.
//

import UIKit

class LanguageResultCell: UITableViewCell {

    @IBOutlet private weak var keyLbl: UILabel!
    @IBOutlet private weak var valueLbl: UILabel!
    @IBOutlet private weak var selectStatusButton: UIButton!
    @IBOutlet private weak var numLbl: UILabel!
    
    var model: LanguageModel? {
        didSet {
            keyLbl.text = model?.key
            valueLbl.text = model?.value
            
            if model?.key == model?.value || (model?.value ?? "").contains(model?.key ?? "") {
                keyLbl.textColor = .red
                valueLbl.textColor = .red
            } else {
                keyLbl.textColor = .black
                valueLbl.textColor = .white
            }
        }
    }
    var row: Int = 0 {
        didSet {
            numLbl.text = "\(row + 1)"
        }
    }
    var isModelSelect: Bool = false {
        didSet {
            selectStatusButton.isSelected = isModelSelect
        }
    }
    var modelSelectChangeBlock: ((_ languageModel: LanguageModel?) -> Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        backgroundColor = .white
        selectionStyle = .none
    }
    
    @IBAction private func selectButtonAction(_ sender: Any) {
        modelSelectChangeBlock?(model)
    }
    
    
}
